#include "WifiLeafForm.h"

WifiLeafForm::WifiLeafForm(ElementForm* parent)
	:LeafForm(parent)
{

}

void WifiLeafForm::setWifiName(const QString& name)
{
	if (name != _wifiName) {
		_wifiName = name;
		update();
	}
}

void WifiLeafForm::setWifiPasswd(const QString& passwd)
{
	if (passwd != _wifiPasswd) {
		_wifiPasswd = passwd;
		update();
	}
}

void WifiLeafForm::paintEvent(QPaintEvent* event)
{

	QPainter painter(this);
	painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing, true);

	{
		QBrush brush(QColor(34, 34, 36, 255));
		painter.setBrush(brush);
		QPen pen(QColor(34, 34, 36, 255));
		painter.setPen(pen);
		painter.drawEllipse(148, 61, 60, 60);
		painter.drawRect(178, 61, 184, 60);
		painter.drawEllipse(332, 61, 60, 60);
	}

	{
		QTextOption option(Qt::AlignHCenter | Qt::AlignVCenter);
		option.setWrapMode(QTextOption::NoWrap);

		QFont font;
		font.setPixelSize(18);
		font.setFamily("Source Han Sans K");
		painter.setFont(font);
		QPen pen(QColor(255, 255, 255));
		painter.setPen(pen);

		QFontMetrics metrics(font);
		/*QString text = getTranslation(LanguageStr_NS::WIFI) + ":" + _wifiName;
	
		painter.drawText(QRectF(171, 61, 214, 30), text, option);
		text = getTranslation(LanguageStr_NS::PASSWORD) + ":" + _wifiPasswd;
		painter.drawText(QRectF(171, 92, 214, 30), text, option);*/
	}



	Node<UIElement>* head = _elements.currentNode();
	Node<UIElement>* tail = _elements.currentNode();
	for (size_t i = 0; i < (_displayNum - 1) / 2; i++) {
		head = head->prev;
		tail = tail->next;
	}
	Node<UIElement>* temp = head;
	while (temp != tail) {
		temp = temp->prev;
		if (temp->data != nullptr) {
			temp->data->setRect(QRect(0, 0, 0, 0));
		}
	}

	for (int i = 0; i < _displayNum; i++)
	{
		head = head->next;
		if (head->prev->data != nullptr) {
			QRect rect = QRect(_leftDistance, _topDistance + i * (44 + 30), width() - _leftDistance, 35);
			head->prev->data->drawElement(this, &painter, i == (_displayNum - 1) / 2, rect);
		}
	}

	ContainsExitForm::paintEvent(event);
}
